#pragma once

#include "highfive/H5File.hpp"

#include "DBManager/IRepository/Input/Dynamic/ISPSELRepository.h"
#include "DBManager/Repository/HDF5/Base/MainlyRepositoryBase.h"
SG_DBMANAGER_HDF5_NAMESPACE_OPEN
namespace SPSEL
{
    struct IDENTITY
    {
        SG::DataStructure::Common::I64 RECNO       = 0;      ///<
        SG::DataStructure::Common::I64 DAMPL       = 0;      ///<
        SG::DataStructure::Common::I64 FREQL       = 0;      ///<
        SG::DataStructure::Common::I64 G_POS = 0;      ///<
        SG::DataStructure::Common::I64 G_LEN = 0;      ///<
        SG::DataStructure::Common::Id  DOMAIN_ID  = 0;      ///<
    };
};  // namespace SPSEL
SG_DBMANAGER_HDF5_NAMESPACE_CLOSE
template <>
inline HighFive::DataType HighFive::create_datatype<SG::DBManager::HDF5::SPSEL::IDENTITY> ()
{
    HighFive::CompoundType compoundType = { { "RECNO", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "DAMPL", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "FREQL", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "G_POS", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "G_LEN", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "DOMAIN_ID", HighFive::create_datatype<SG::DataStructure::Common::Id> () } };
    return compoundType;
}

SG_DBMANAGER_HDF5_NAMESPACE_OPEN
class SPSELRepository : public ISPSELRepository, public SG::DBManager::HDF5::MainlyRepositoryBase<SG::DataStructure::FEM::SPSELData>
{
    using MainStruct      = SG::DataStructure::FEM::SPSELData;
    using SubStruct = SG::DataStructure::Common::I64;

    using NasMainStruct = SG::DBManager::HDF5::SPSEL::IDENTITY;

  public:
    explicit SPSELRepository (HDF5Database& database);

    enum DATASET : std::uint8_t
    {
        MainDataset,
        IndexDataset,
        SubDataset
    };

    /**
     * @brief   : 初始化表数据
     * @author  : wuxingchuang
     */
    void InitialDatasetInfo () override;

    /**
     * @brief   : 将缓存数据转储到文件内
     */
    void DumpWriteCahce () override;

    /**
     * @brief   : 加载文件数据至缓存
     * @param   : loadIndex
     */
    std::vector<DataType>* LoadReadCache (std::size_t loadIndex) override;

    /**
     * @brief   : 对数据进行排序
     */
    void SortData () override;

    /**
     * @brief   : 获取所有数据
     */
    std::vector<MainStruct> GetAllData () override;

    /**
     * @brief   : 将自己的数据转存为nastran的数据结构
     */
    void OwnToNastran (std::vector<MainStruct>&           own,
                       std::vector<NasMainStruct>& _OUT   IDENTITYData,
                       std::vector<SubStruct>& _OUT subDataTABLES,

                       bool isSort = false);

    /**
     * @brief   : 将NASTRAN的数据转存为自己的数据结构
     * @param   : IDENTITYData
     * @param   : subData
     * @param   : own
     */
    void
    NastranToOwn (std::vector<NasMainStruct>& IDENTITYData, std::vector<SubStruct>& subDataTABLES, std::vector<MainStruct>& _OUT own);
};
SG_DBMANAGER_HDF5_NAMESPACE_CLOSE
